package org.zsl.controller.springmvc;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import org.zsl.model.ResponseMsg;
import org.zsl.model.User;
import org.zsl.service.UserRestfulService;

import java.util.List;

@RestController
@RequestMapping("/rest")
public class RestfelController {
    @Autowired
    private UserRestfulService service;

    @RequestMapping(value="/add",method = RequestMethod.POST)
    public ResponseMsg add(User user) {

        return service.add(user);
    }
    @RequestMapping(value="/edit",method = RequestMethod.PUT)
    public ResponseMsg edit(User user){
        return service.edit(user);
    }
    @RequestMapping(value="/remove/{userId}",method = RequestMethod.DELETE)
    public ResponseMsg remove(@PathVariable("userId") Integer userId){

        System.out.println(userId);
        return  service.remove(userId);
    }
    @RequestMapping(value="/list",method = RequestMethod.GET)
    public List<User> getList(){
        return  service.getList();
    }
    @RequestMapping(value="/remove/{userId}",method = RequestMethod.GET)
    public  User getUserById(@PathVariable("userId") Integer userId){
        return service.getSingle(userId);
    }
}
